package framework.utils;

public class ConvertUtil {

    public static int toInteger(Object obj) {
        String str = obj == null ? "0" : obj.toString();
        int i = Integer.parseInt(str);
        return i;
    }

    public static long toLong(Object obj) {
        String str = obj == null ? "0" : obj.toString();
        long l = Long.parseLong(str);
        return l;
    }

    public static String toString(Object obj) {
        if (obj == null) return null;
        String s = obj.toString();
        return s;
    }

    public static boolean toBoolean(Object obj) {
        String str = obj == null ? "false" : obj.toString();
        boolean b = Boolean.parseBoolean(str);
        return b;
    }

    public static void main(String[] arg) {
        System.out.println(toInteger(null));
        System.out.println(toInteger("123"));
        System.out.println(toString(456.2));
        System.out.println(toBoolean("true"));
    }

}
